package com.lengyu.vxminiprogram.controller;


import com.lengyu.vxminiprogram.common.HttpResultDto;
import com.lengyu.vxminiprogram.convert.IWorkOrderProcConverter;
import com.lengyu.vxminiprogram.dto.WorkOrderProcDto;
import com.lengyu.vxminiprogram.entity.WorkOrder;
import com.lengyu.vxminiprogram.entity.WorkOrderProc;
import com.lengyu.vxminiprogram.service.IWorkOrderProcService;
import com.lengyu.vxminiprogram.service.IWorkOrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuyu
 * @since 2024-11-28
 */
@RestController
@RequestMapping("/work-order-proc")
public class WorkOrderProcController {
    @Autowired
    IWorkOrderService workOrderService;

    @Autowired
    IWorkOrderProcService workProcService;

    @Autowired
    IWorkOrderProcConverter workOrderProcConverter;

    @PostMapping(value="/save")
    public HttpResultDto<String> save(@RequestBody WorkOrderProcDto workOrderProcDto) {
        if (StringUtils.isBlank(workOrderProcDto.getWorkOrderId())) {
            return HttpResultDto.failed("没有工单ID");
        } else {
            WorkOrderProc workOrderProc = workOrderProcConverter.dtoToEntity(workOrderProcDto);
            WorkOrder workOrder = workOrderService.getById(workOrderProc.getWorkOrderId());
            if (workOrder != null) {
                workOrder.setCurrentStatus(workOrderProcDto.getCurrentStatus());
            }
            workOrderService.updateById(workOrder);
            workProcService.saveOrUpdate(workOrderProc);

        }

        return HttpResultDto.success();
    }
}
